/**
 * 
 */
package account;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

/**
 * @author haiyuzha
 *
 */
public class SearchDialog extends JFrame {
	private JTextField textField = null;

	/**
	 * @throws HeadlessException
	 */
	public SearchDialog() throws HeadlessException {
		setMinimumSize(new Dimension(150, 100));
		setPreferredSize(new Dimension(150, 100));

		Container cp = getContentPane();
		cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
		
		textField = new JTextField();
		textField.setFont(new Font(null, Font.ITALIC, 12));
		textField.setPreferredSize(new Dimension(20, 20));
		textField.setMaximumSize(new Dimension(200, 25));
		textField.addFocusListener(new TextFieldFocusListener(textField));
		textField.getDocument().addDocumentListener(new TextEventListener(textField));
		
		JButton jb0 = new JButton("Search");

		cp.add(textField);
		cp.add(jb0);
	}

	/**
	 * @param gc
	 */
	public SearchDialog(GraphicsConfiguration gc) {
		super(gc);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param title
	 * @throws HeadlessException
	 */
	public SearchDialog(String title) throws HeadlessException {
		super(title);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param title
	 * @param gc
	 */
	public SearchDialog(String title, GraphicsConfiguration gc) {
		super(title, gc);
		// TODO Auto-generated constructor stub
	}

	class TextEventListener implements DocumentListener {
		private JTextField textField = null;

		TextEventListener(JTextField tf) {
			textField = tf;
		}

		@Override
		public void changedUpdate(DocumentEvent arg0) {
			System.out.print(arg0.getDocument().toString());
		}

		@Override
		public void insertUpdate(DocumentEvent arg0) {
		}

		@Override
		public void removeUpdate(DocumentEvent arg0) {
			// TODO Auto-generated method stub

		}
	}

	class TextFieldFocusListener implements FocusListener {
		private JTextField textField = null;

		TextFieldFocusListener(JTextField tf) {
			textField = tf;
		}

		@Override
		public void focusGained(FocusEvent arg0) {
			textField.selectAll();
			textField.setFont(new Font(null, Font.PLAIN, 12));
			textField.setText("");
		}

		@Override
		public void focusLost(FocusEvent arg0) {
			textField.setText("#Input search string");
			textField.setFont(new Font(null, Font.ITALIC, 12));
		}
	}
}
